<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Python," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;序列是 Python 中最基本的数据结构。序列中的每个元素都分配一个数字-它的位置，或索引，第一个索引就是0，第二个索引是1，依此类推。&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Python 有6个序列的内置类型，但最常见的是列表和元组。&amp;#160;">
<meta name="keywords" content="Python">
<meta property="og:type" content="article">
<meta property="og:title" content="Python 列表（list）">
<meta property="og:url" content="https://hcldirgit.github.io/2017/08/10/Python/1. Python 基础篇/1. Python 基础语法/1.7 列表/9. Python 的列表(list)/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;序列是 Python 中最基本的数据结构。序列中的每个元素都分配一个数字-它的位置，或索引，第一个索引就是0，第二个索引是1，依此类推。&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Python 有6个序列的内置类型，但最常见的是列表和元组。&amp;#160;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-06-19T13:38:12.253Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Python 列表（list）">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;序列是 Python 中最基本的数据结构。序列中的每个元素都分配一个数字-它的位置，或索引，第一个索引就是0，第二个索引是1，依此类推。&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Python 有6个序列的内置类型，但最常见的是列表和元组。&amp;#160;">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/08/10/Python/1. Python 基础篇/1. Python 基础语法/1.7 列表/9. Python 的列表(list)/"/>





  <title>Python 列表（list） | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/08/10/Python/1. Python 基础篇/1. Python 基础语法/1.7 列表/9. Python 的列表(list)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Python 列表（list）</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-10T14:00:36+08:00">
                2017-08-10
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;序列是 Python 中最基本的数据结构。序列中的每个元素都分配一个数字-它的位置，或索引，第一个索引就是0，第二个索引是1，依此类推。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Python 有6个序列的内置类型，但最常见的是列表和元组。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;序列都可以进行的操作包括索引、切片、加、乘、检查成员。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;此外，Python 已经内置确定序列的长度以及确定最大和最小的元素的方法。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列表是最常用的 Python 的数据类型，它可以作为一个方括号内的逗号分割值出现。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列表的数据项不需要具有相同的类型。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列表是处理一组有序项目的数据结构，即可以在列表中存储一个序列的项目。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列表是可变类型的数据。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建一个列表，只要把逗号分隔的不同的数据项使用方括号括起来即可。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">In [<span class="number">49</span>]: list1 = [<span class="string">'python'</span>,<span class="string">'linxu'</span>,<span class="number">1997</span>,<span class="number">2000</span>]</div><div class="line"></div><div class="line">In [<span class="number">50</span>]: list2 = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</div><div class="line"></div><div class="line">In [<span class="number">51</span>]: list3 = [<span class="string">"a"</span>,<span class="string">"b"</span>,<span class="string">"c"</span>,<span class="string">"d"</span>];</div><div class="line">In [<span class="number">52</span>]: list4 = [<span class="string">'a'</span>,<span class="number">1</span>,(<span class="number">4</span>,),[<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>]];</div><div class="line"></div><div class="line">In [<span class="number">53</span>]: type(list1)</div><div class="line">Out[<span class="number">53</span>]: list</div><div class="line"></div><div class="line">In [<span class="number">54</span>]: type(list2)</div><div class="line">Out[<span class="number">54</span>]: list</div><div class="line"></div><div class="line">In [<span class="number">55</span>]: type(list3)</div><div class="line">Out[<span class="number">55</span>]: list</div><div class="line"></div><div class="line">In [<span class="number">56</span>]: type(list4)</div><div class="line">Out[<span class="number">56</span>]: list</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建一个空的列表</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">In [<span class="number">57</span>]: list5 = []</div><div class="line"></div><div class="line">In [<span class="number">58</span>]: type(list5)</div><div class="line">Out[<span class="number">58</span>]: list</div><div class="line"></div><div class="line">In [<span class="number">59</span>]: list6 = list()</div><div class="line"></div><div class="line">In [<span class="number">60</span>]: type(list6)</div><div class="line">Out[<span class="number">60</span>]: list</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列表中追加值</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">In [<span class="number">61</span>]: list5.append(<span class="string">'hello'</span>)</div><div class="line"></div><div class="line">In [<span class="number">62</span>]: list5</div><div class="line">Out[<span class="number">62</span>]: [<span class="string">'hello'</span>]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;更改列表中一个值</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">In [<span class="number">63</span>]: list4</div><div class="line">Out[<span class="number">63</span>]: [<span class="string">'a'</span>, <span class="number">1</span>, (<span class="number">4</span>,), [<span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>]]</div><div class="line"></div><div class="line">In [<span class="number">64</span>]: list4[<span class="number">0</span>] = <span class="string">'b'</span></div><div class="line"></div><div class="line">In [<span class="number">65</span>]: list4</div><div class="line">Out[<span class="number">65</span>]: [<span class="string">'b'</span>, <span class="number">1</span>, (<span class="number">4</span>,), [<span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>]]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;将两个列表变成一个大的列表</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">In [<span class="number">66</span>]: list4 + list5</div><div class="line">Out[<span class="number">66</span>]: [<span class="string">'b'</span>, <span class="number">1</span>, (<span class="number">4</span>,), [<span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>], <span class="string">'hello'</span>]</div></pre></td></tr></table></figure>
<h2 id="访问列表中的值"><a href="#访问列表中的值" class="headerlink" title="访问列表中的值"></a>访问列表中的值</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用下标索引来访问列表中的值，同样也可以使用方括号的形式截取字符</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#!/usr/bin/python</span></div><div class="line"></div><div class="line">list1 = [<span class="string">'physics'</span>, <span class="string">'chemistry'</span>, <span class="number">1997</span>, <span class="number">2000</span>];</div><div class="line">list2 = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span> ];</div><div class="line"></div><div class="line"><span class="keyword">print</span> <span class="string">"list1[0]: "</span>, list1[<span class="number">0</span>]</div><div class="line"><span class="keyword">print</span> <span class="string">"list2[1:5]: "</span>, list2[<span class="number">1</span>:<span class="number">5</span>]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;实例输出结果</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">list[<span class="number">0</span>]: physics</div><div class="line">list2[<span class="number">1</span>:<span class="number">5</span>]: [<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>]</div></pre></td></tr></table></figure>
<h2 id="更新列表"><a href="#更新列表" class="headerlink" title="更新列表"></a>更新列表</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以对列表的数据项进行修改或更新，也可以使用 append() 方法来添加列表项。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#!/usr/bin/python</span></div><div class="line"></div><div class="line">list = [<span class="string">'physics'</span>, <span class="string">'chemistry'</span>, <span class="number">1997</span>, <span class="number">2000</span>];</div><div class="line"></div><div class="line"><span class="keyword">print</span> <span class="string">"Value available at index 2 : "</span></div><div class="line"><span class="keyword">print</span> list[<span class="number">2</span>];</div><div class="line">list[<span class="number">2</span>] = <span class="number">2001</span>;</div><div class="line"><span class="keyword">print</span> <span class="string">"New value available at index 2 : "</span></div><div class="line"><span class="keyword">print</span> list[<span class="number">2</span>];</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;实例输出结果</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">Value available at index <span class="number">2</span> :</div><div class="line"><span class="number">1997</span></div><div class="line">New value available at index <span class="number">2</span> :</div><div class="line"><span class="number">2001</span></div></pre></td></tr></table></figure>
<h2 id="删除列表元素"><a href="#删除列表元素" class="headerlink" title="删除列表元素"></a>删除列表元素</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以使用 del 语句来删除列表的元素。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#!/usr/bin/python</span></div><div class="line"></div><div class="line">list1 = [<span class="string">'physics'</span>, <span class="string">'chemistry'</span>, <span class="number">1997</span>, <span class="number">2000</span>];</div><div class="line"></div><div class="line"><span class="keyword">print</span> list1;</div><div class="line"><span class="keyword">del</span> list1[<span class="number">2</span>];</div><div class="line"><span class="keyword">print</span> <span class="string">"After deleting value at index 2 : "</span></div><div class="line"><span class="keyword">print</span> list1;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;实例输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[<span class="string">'physics'</span>, <span class="string">'chemistry'</span>, <span class="number">1997</span>, <span class="number">2000</span>]</div><div class="line">After deleting value at index <span class="number">2</span> :</div><div class="line">[<span class="string">'physics'</span>, <span class="string">'chemistry'</span>, <span class="number">2000</span>]</div></pre></td></tr></table></figure>
<h2 id="Python-列表脚本操作符"><a href="#Python-列表脚本操作符" class="headerlink" title="Python 列表脚本操作符"></a>Python 列表脚本操作符</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列表对 + 和 <em> 的操作符与字符串相似。+ 号用于组合列表， </em> 号用于重复列表。</p>
<table>
<thead>
<tr>
<th>Python表达式</th>
<th>结果</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>len([1,2,3])</td>
<td>3</td>
<td>长度</td>
</tr>
<tr>
<td>[1,2,3] + [4,5,6]</td>
<td>[1,2,3,4,5,6]</td>
<td>组合</td>
</tr>
<tr>
<td>[‘Hi!’] * 4</td>
<td>[‘Hi!’,’Hi!’,’Hi!’,’Hi!’]</td>
<td>重复</td>
</tr>
<tr>
<td>3 in [1,2,3]</td>
<td>true</td>
<td>元素是否存在于列表中</td>
</tr>
<tr>
<td>for x in [1,2,3]:print x,</td>
<td>1 2 3</td>
<td>迭代</td>
</tr>
</tbody>
</table>
<h2 id="Python-列表截取"><a href="#Python-列表截取" class="headerlink" title="Python 列表截取"></a>Python 列表截取</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Python 的列表截取实例：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&gt;&gt;&gt; </span>L = [<span class="string">'Google'</span>, <span class="string">'Runoob'</span>, <span class="string">'Taobao'</span>]</div><div class="line"><span class="meta">&gt;&gt;&gt; </span>L[<span class="number">2</span>]</div><div class="line"><span class="string">'Taobao'</span></div><div class="line"><span class="meta">&gt;&gt;&gt; </span>L[<span class="number">-2</span>]</div><div class="line"><span class="string">'Runoob'</span></div><div class="line"><span class="meta">&gt;&gt;&gt; </span>L[<span class="number">1</span>:]</div><div class="line">[<span class="string">'Runoob'</span>, <span class="string">'Taobao'</span>]</div><div class="line">&gt;&gt;&gt;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;描述</p>
<table>
<thead>
<tr>
<th>Python 表达式</th>
<th>结果</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>L[2]</td>
<td>‘Taobao’</td>
<td>读取列表中第三个元素</td>
</tr>
<tr>
<td>L[-2]</td>
<td>‘Runoob’</td>
<td>读取列表中倒数第二个元素</td>
</tr>
<tr>
<td>L[1:]</td>
<td>[‘Runoob’,’Taobao’]</td>
<td>从第儿歌元素开始截取列表</td>
</tr>
</tbody>
</table>
<h2 id="Python-列表函数-amp-方法"><a href="#Python-列表函数-amp-方法" class="headerlink" title="Python 列表函数&amp;方法"></a>Python 列表函数&amp;方法</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Python 包含以下函数：</p>
<table>
<thead>
<tr>
<th>序号</th>
<th>函数</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/python%E5%88%97%E8%A1%A8%E5%87%BD%E6%95%B0/1.%20Python%20List%20cmp(" target="_blank" rel="external">cmp(list1,list2)</a>%E6%96%B9%E6%B3%95.md),比较两个列表的元素</td>
</tr>
<tr>
<td>2</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/python%E5%88%97%E8%A1%A8%E5%87%BD%E6%95%B0/2.%20Python%20List%20len(" target="_blank" rel="external">len(list)</a>%E6%96%B9%E6%B3%95.md),列表元素个数</td>
</tr>
<tr>
<td>3</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/python%E5%88%97%E8%A1%A8%E5%87%BD%E6%95%B0/3.%20Python%20List%20max(" target="_blank" rel="external">max(list)</a>%E6%96%B9%E6%B3%95.md),返回列表元素最大值</td>
</tr>
<tr>
<td>4</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/python%E5%88%97%E8%A1%A8%E5%87%BD%E6%95%B0/4.%20Python%20List%20min(" target="_blank" rel="external">min(list)</a>%E6%96%B9%E6%B3%95.md),返回列表元素最小值</td>
</tr>
<tr>
<td>5</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/python%E5%88%97%E8%A1%A8%E5%87%BD%E6%95%B0/5.%20Python%20List%20list(" target="_blank" rel="external">list(seq)</a>%E6%96%B9%E6%B3%95.md),将元组转换为列表</td>
</tr>
</tbody>
</table>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Python 包含以下方法</p>
<table>
<thead>
<tr>
<th>序号</th>
<th>方法</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/1.%20Python%20List%20append(" target="_blank" rel="external">list.append(obj)</a>%E6%96%B9%E6%B3%95.md),在列表末尾添加新的对象</td>
</tr>
<tr>
<td>2</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/2.%20Python%20List%20count(" target="_blank" rel="external">list.count(obj)</a>%E6%96%B9%E6%B3%95.md),统计某个元素在列表中出现的次数</td>
</tr>
<tr>
<td>3</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/3.%20Python%20List%20extend(" target="_blank" rel="external">list.extend(seq)</a>%E6%96%B9%E6%B3%95.md),在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）</td>
</tr>
<tr>
<td>4</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/4.%20Python%20List%20index(" target="_blank" rel="external">list.index(obj)</a>%E6%96%B9%E6%B3%95.md),从列表中找出某个值第一个匹配项的索引位置</td>
</tr>
<tr>
<td>5</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/5.%20Python%20List%20insert(" target="_blank" rel="external">list.insert(index, obj)</a>%E6%96%B9%E6%B3%95.md),将对象插入列表</td>
</tr>
<tr>
<td>6</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/6.%20Python%20List%20pop(" target="_blank" rel="external">list.pop(obj=list[-1])</a>%E6%96%B9%E6%B3%95.md),移除列表中的一个元素（默认最后一个元素），并且返回该元素的值</td>
</tr>
<tr>
<td>7</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/7.%20Python%20List%20remove(" target="_blank" rel="external">list.remove(obj)</a>%E6%96%B9%E6%B3%95.md),移除列表中某个值的第一个匹配项</td>
</tr>
<tr>
<td>8</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/8.%20Python%20List%20reverse(" target="_blank" rel="external">list.reverse()</a>%E6%96%B9%E6%B3%95.md),反向列表中元素</td>
</tr>
<tr>
<td>9</td>
<td><a href="https://github.com/hcldirgit/studygit/blob/master/Python%E5%88%97%E8%A1%A8%E6%96%B9%E6%B3%95/9.%20Python%20List%20sort(" target="_blank" rel="external">list.sort([func])</a>%E6%96%B9%E6%B3%95.md),对厡列表进行排序</td>
</tr>
</tbody>
</table>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Python/" rel="tag"># Python</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/08/10/Python/1. Python 基础篇/1. Python 基础语法/2.0 2.1 流程控制-if条件/12. Python 流程控制-if 条件语句/" rel="next" title="Python 流程控制- if 条件语句">
                <i class="fa fa-chevron-left"></i> Python 流程控制- if 条件语句
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/08/10/Python/1. Python 基础篇/1. Python 基础语法/2.2 流程控制-for 序列/14. Python 流程控制- for 循环序列/" rel="prev" title="Python 流程控制-for循环序列">
                Python 流程控制-for循环序列 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#访问列表中的值"><span class="nav-number">1.</span> <span class="nav-text">访问列表中的值</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#更新列表"><span class="nav-number">2.</span> <span class="nav-text">更新列表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#删除列表元素"><span class="nav-number">3.</span> <span class="nav-text">删除列表元素</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Python-列表脚本操作符"><span class="nav-number">4.</span> <span class="nav-text">Python 列表脚本操作符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Python-列表截取"><span class="nav-number">5.</span> <span class="nav-text">Python 列表截取</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Python-列表函数-amp-方法"><span class="nav-number">6.</span> <span class="nav-text">Python 列表函数&方法</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
